home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / sndforever / sndforever.cp next >
Encoding:
Text File  |  2000-06-23  |  2.5 KB  |  105 lines

  1. /*
  2.     File:        SndForEver.cp
  3.  
  4.     Contains:    This application demonstrates how to play a snd which has a loop in it.
  5.  
  6.                 The resource which I am using for the 'snd ' is 128 and this resource has been 
  7.                 pre-parsed. I took out some of it so that I would be able to make the code for playing 
  8.                 the sound easier to follow.  The part of the header which I have taken out is the 
  9.  
  10.                 format
  11.                 # of Synths
  12.                 Synth resource ID
  13.                 Init option
  14.                 # of commands
  15.                 the command
  16.                 its params
  17.  
  18.                 The original un-cut resource is in resource 100.
  19.  
  20.                 To use the snippet, just double click on it and when you are sick of listening to it, 
  21.                 just click the mouse button.  
  22.  
  23.     Written by:     
  24.  
  25.     Copyright:    Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
  26.  
  27.                 You may incorporate this Apple sample source code into your program(s) without
  28.                 restriction. This Apple sample source code has been provided "AS IS" and the
  29.                 responsibility for its operation is yours. You are not permitted to redistribute
  30.                 this Apple sample source code as "Apple sample source code" after having made
  31.                 changes. If you're going to re-distribute the source, we require that you make
  32.                 it clear in the source that the code was descended from Apple sample source
  33.                 code, but that you've made changes.
  34.  
  35.     Change History (most recent first):
  36.                 8/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  37.                 
  38.  
  39. */
  40. #include    <Resources.h>
  41. #include    <Sound.h>
  42. #include    <Events.h>
  43. #include    <Memory.h>
  44.  
  45. #define    TRUE            0xFF
  46. #define    FALSE            0
  47.  
  48. main()
  49. {
  50.     Handle            SoundData;
  51.     SndChannelPtr    chan;
  52.     OSErr            err;
  53.     SndCommand        mycmd;
  54.     
  55.     SoundData = GetResource ('snd ', 128);
  56.     if (ResError() != noErr || SoundData == nil)
  57.         Debugger();
  58.     HLock (SoundData);
  59.             
  60.     mycmd.cmd = soundCmd;
  61.     mycmd.param1 = 0;
  62.     mycmd.param2 = (long) *SoundData;
  63.     
  64.     chan = nil;
  65.     err = SndNewChannel (&chan, sampledSynth, 0, nil);
  66.     if (err != noErr)
  67.         Debugger();
  68.     
  69.     err = SndDoImmediate (chan, &mycmd);
  70.     if (err != noErr)
  71.         Debugger();
  72.  
  73.     mycmd.cmd = freqCmd;
  74.     mycmd.param1 = 0;
  75.     mycmd.param2 = 60;
  76.     
  77.     err = SndDoCommand (chan, &mycmd, FALSE);
  78.     if (err != noErr)
  79.         Debugger();
  80.  
  81.     do {
  82.         /*mycmd.cmd = noteCmd;
  83.         mycmd.param1 = 0x1000;
  84.         mycmd.param2 = 60;
  85.     
  86.         err = SndDoCommand (chan, &mycmd, FALSE);
  87.         if (err != noErr)
  88.             Debugger();*/
  89.         
  90.         } while (!StillDown());
  91.         
  92.     mycmd.cmd = quietCmd;
  93.     mycmd.param1 = 0;
  94.     mycmd.param2 = 0;
  95.     
  96.     err = SndDoImmediate (chan, &mycmd);
  97.     if (err != noErr)
  98.         Debugger();
  99.  
  100.     err = SndDisposeChannel (chan,FALSE);
  101.     if (err != noErr)
  102.         Debugger();
  103.         
  104.     HUnlock (SoundData);
  105. }